﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace DataAccessApplicationBlockGettingStarted
{
    public class GettingStartedBusinessLogic : IDisposable
    {
        private DataLayer model = null;

        public void Initialize()
        {
            model = new DataLayer();
            model.Initialize();

            // Now insert some records - use two different techniques
            model.InsertCustomerTSQL("Andy Wigley", "Consultant");

            // A much faster technique is to use a SqlCeResultSet - this is the best way
            // so has been implemented in a separate method
            model.InsertCustomers(new List<Customer> 
                {new Customer () { Name = "Andrej Radinger", Title = "Consultant"},
                 new Customer () { Name = "Steve Ballmer", Title = null}
                });

            model.InsertCustomersInTransaction(new List<Customer> 
                {new Customer () { Name = "Peter Foot", Title = "Consultant"},
                 new Customer () { Name = "Pete Vickers", Title = null}
                });
        }

        public List<Customer> GetCustomers()
        {
            // Get the customer list from the model
            return model.GetCustomers();
        }

        public void SaveCustomer(Customer customer)
        {
            model.SaveCustomer(customer);
        }

        #region IDisposable Members

        // Class implements IDisposable so that the database object can be disposed correctly
        public void Dispose()
        {
            model.Dispose();
            model = null;
        }

        #endregion

    }
}
